Skip to content

feat(static-assets): add PrivateStaticAssetsConstruct (private bucket, CloudFront OAC, optional DNS, immutable deployment) - #116

Merged
ncipollina merged 7 commits into
mainfrom
feat/v3-private-static-assets
Nov 24, 2026
Merged

ncipollina merged 7 commits into
mainfrom
feat/v3-private-static-assets

Conversation

@ncipollina

@ncipollina ncipollina commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Closes #111

Beads: cdkc-2lh.4 (epic cdkc-2lh). Design: docs/designs/v3-modernization.md §8 (owner-approved 2026-11-24, name PrivateStaticAssetsConstruct).

Summary

A new PrivateStaticAssetsConstruct for immutable, versioned web assets behind CloudFront. StaticSiteConstruct is unchanged.

  • Bucket: Block Public Access on, SSE-S3, SSL-only, versioned, no website endpoint. RemovalPolicy is configurable and defaults to RETAIN; no auto-delete.
  • CloudFront:
    • S3BucketOrigin.WithOriginAccessControl; the bucket policy grants cloudfront.amazonaws.com s3:GetObject conditioned on this distribution's AWS:SourceArn.
    • HTTPS_ONLY by default (redirect optional), CACHING_OPTIMIZED by default (configurable), optional comment.
  • Optional custom DNS (PrivateStaticAssetsDomainOptions, off by default):
    • domain names, plus either a certificate or a zone (HostedZone or HostedZoneName lookup) to create one;
    • A and AAAA alias records per domain;
    • invalid combinations are rejected at synthesis.
  • Optional SPA routing (CloudFront Function), error responses and default root object: all off by default.
  • Deployment: BucketDeployment from AssetPath, with:
    • DestinationKeyPrefix;
    • Prune (default false) and RetainOnDelete (default true);
    • CacheControl (default none);
    • optional InvalidationPaths.
  • Public properties: Bucket, Distribution and DomainName (the first custom domain, otherwise the CloudFront domain).
  • Testing helpers: PrivateStaticAssetsConstructAssertions and PrivateStaticAssetsConstructPropsBuilder.
  • Docs:

Also fixed (stale docs from #109): the Testing guide and the Cognito page still showed the AutoFixture *AutoData attributes, which were deleted with the test migration. They now describe the library's Compono profiles.

Golden templates

  • New: private-static-assets-default.json and private-static-assets-custom-domain.json.
  • Existing goldens are unchanged. The PR modifies no existing source or test file; git diff --diff-filter=M --name-only 53607ea lists only Claude's doc edits.

Validation (actually run)

  • TDD: each behavior was observed failing before its implementation (OpenCode worker evidence). For example, the bucket tests failed with Template has 0 resources with type AWS::S3::Bucket, then OAC/policy, SPA/error responses, deployment and DNS each failed before implementation. Cache-control "none" was caught by a test after an empty array produced cache-control: "".
  • Re-run by Claude on f0c5191:
    • dotnet build LayeredCraft.Cdk.Constructs.slnx -c Release: 0 warnings, 0 errors;
    • dotnet test --solution …: net10.0 651, net11.0 651 passed, 0 failed.
  • Integration with feat(lambda)!: alias name, alias-only permission default, public alias/version, scoped log policy, S3 artifact code #115: git merge-tree reports no conflicts. On the combined tree, the build had 0 warnings and 674 tests passed per TFM, 0 failed (throwaway worktree, removed afterwards).
  • git diff --check: clean.
  • Not run: a local MkDocs build (mkdocs isn't installed locally; the Docs workflow builds on main).

Test-stack audit

  • Compono and Compono.XunitV3; new PrivateStaticAssetsConstructPropsProfile. No new packages.
  • Behavior-defining values (domains, prefixes, cache-control) are literals.
  • Retained: the existing GoldenTemplate harness. Compono does not provide CloudFormation template diffing.

Notes for the owner

Orchestration

  • Implemented by an OpenCode worker (openrouter/deepseek/deepseek-v4.1-flash) in an isolated worktree, limited to new files. The required reads were observed in the worker log.
  • Claude reviewed the diff, re-ran validation and wrote the shared docs.

🤖 Generated with Claude Code

ncipollina and others added 5 commits November 24, 2026 07:25
…utoData docs

- mkdocs nav, README, docs index, CLAUDE.md and the Testing guide (builder
  and assertions) for the new construct
- construct page: CloudFront certificates must be in us-east-1; DESTROY
  cannot delete a non-empty versioned bucket; neutral example heading
- Testing guide and Cognito page: replace the AutoFixture *AutoData
  attribute sections (removed with the test-project migration in #109)
  with a note on the library's Compono profiles

Refs #111

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ncipollina ncipollina added this to the v3.0.0 milestone Nov 24, 2026
@ncipollina ncipollina added the ✨ enhancement New feature or request label Nov 24, 2026
@github-actions github-actions Bot added the type: feat New feature label Nov 24, 2026
@ncipollina

Copy link
Copy Markdown
Contributor Author

@codex review — focus: (1) security of the bucket and its access: Block Public Access, SSL-only, OAC-only access with the bucket policy scoped to this distribution's AWS:SourceArn, no public principal; (2) DNS option validation and certificate creation (CloudFront needs us-east-1); (3) BucketDeployment defaults (prune false, retain true, no cache-control and no invalidation unless set); (4) public API naming and XML docs consistency with the existing constructs.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T12:50:59.742583Z 134c34d Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8833ffd7fa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +190 to +191
certificate = domain.Certificate
?? new Certificate(this, $"{id}-certificate", new CertificateProps

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject automatic certificate creation outside us-east-1

When a custom domain supplies a hosted zone but no certificate in a stack outside us-east-1, this creates the certificate in the stack's region and passes it directly to CloudFront. CloudFront requires viewer ACM certificates in us-east-1, so this configuration produces an undeployable distribution. Although the construct page documents the regional restriction, ResolveDomain does not enforce it. Reject a known non-us-east-1 stack region before creating the certificate, with an error directing callers to supply a certificate from us-east-1, or explicitly create the certificate in that region.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 134c34d: when no Certificate is supplied and the stack region is resolved and not us-east-1, construction now throws ArgumentException directing callers to supply a us-east-1 certificate. A supplied certificate is accepted in any region; an environment-agnostic stack (unresolved region) cannot be checked at synthesis and keeps the previous behavior (documented). Test-first: Construct_ShouldThrowWhenCreatingCertificateOutsideUsEast1 observed failing (no exception thrown) before the fix; 655 tests pass per TFM; existing goldens unchanged.

@ncipollina ncipollina changed the title feat(static-assets): PrivateStaticAssetsConstruct (private bucket, CloudFront OAC, optional DNS, immutable deployment) feat(static-assets): add PrivateStaticAssetsConstruct (private bucket, CloudFront OAC, optional DNS, immutable deployment) Nov 24, 2026
@ncipollina

Copy link
Copy Markdown
Contributor Author

@codex review — re-review 134c34d (us-east-1 certificate guard) for the finding above.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 134c34da55

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨ enhancement New feature or request type: feat New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3.0.0: private static-assets construct (Block Public Access, CloudFront OAC, optional DNS, immutable deployment)

1 participant